//
//  LrcTool.m
//  老司机发车了标准版
//
//  Created by SuperNing on 16/8/10.
//  Copyright © 2016年 斌. All rights reserved.
//

#import "LrcTool.h"
#import "LrcLine.h"
@implementation LrcTool

+ (NSArray *)lrcToolWithLrcNameOne:(NSString *)lrcName
{
    // 1.获取路径
    NSString *path = [[NSBundle mainBundle] pathForResource:lrcName ofType:nil];
    
    
    // 2.获取歌词
    NSString *lrcString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    
    
    
    // 3.转化成歌词数组
    NSArray *lrcArray = [lrcString componentsSeparatedByString:@"\n"];
    NSMutableArray *tempArray = [NSMutableArray array];
    for (NSString *lrcLineString in lrcArray) {
        
        /*
         [ti:简单爱]
         [ar:周杰伦]
         [al:范特西]
         
         */
        // 4.过滤不需要的字符串
        if ([lrcLineString hasPrefix:@"[ti:"] ||
            [lrcLineString hasPrefix:@"[ar:"] ||
            [lrcLineString hasPrefix:@"[al:"] ||
            ![lrcLineString hasPrefix:@"["]) {
            continue;
        }
        
        // 5.将歌词转化成模型
        LrcLine *lrcLine = [LrcLine LrcLineString:lrcLineString];
        [tempArray addObject:lrcLine];
    }
    
    return tempArray;
}

+ (NSArray *)lrcToolWithLrcNameTwo:(NSString *)lrcStr{
    
    NSURL *lrcUrl = [NSURL URLWithString:lrcStr];
//    NSData *lrcData = [NSData dataWithContentsOfURL:lrcUrl];
//    NSString *lrcString = [[NSString alloc] initWithData:lrcData encoding:NSUTF8StringEncoding];
    NSString *lrcString = [NSString stringWithContentsOfURL:lrcUrl encoding:NSUTF8StringEncoding error:nil];
    
    // 3.转化成歌词数组
    NSArray *lrcArray = [lrcString componentsSeparatedByString:@"\n"];
    NSMutableArray *tempArray = [NSMutableArray array];
    for (NSString *lrcLineString in lrcArray) {
        
        /*
         [ti:简单爱]
         [ar:周杰伦]
         [al:范特西]
         
         */
        // 4.过滤不需要的字符串
        if ([lrcLineString hasPrefix:@"[ti:"] ||
            [lrcLineString hasPrefix:@"[ar:"] ||
            [lrcLineString hasPrefix:@"[al:"] ||
            ![lrcLineString hasPrefix:@"["]) {
            continue;
        }
        
        // 5.将歌词转化成模型
        LrcLine *lrcLine = [LrcLine LrcLineString:lrcLineString];
        [tempArray addObject:lrcLine];
    }
    
    return tempArray;

}




@end
